package fr.ssd.sic.ui;

import java.awt.Color;
import java.awt.Component;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Flags.Flag;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableCellRenderer;

class MailTableModel extends AbstractTableModel {


	private static final long serialVersionUID = -610847746211822670L;

	protected static final String[] columnNames = { "Status", "Subject", "Sender", "Date" };

	protected static final int COLUMN_COUNT = 4;

	protected static final Class thisClass = MailTableModel.class;

	protected Message[] data = new Message[0];

	public Message getMessage(int row){
		return data[row];
	}
	public void setData(Message[] data) {
		this.data = data;
		fireTableDataChanged();
	}

	// Implementation of TableModel interface
	public int getRowCount() {
		return data.length;
	}

	public int getColumnCount() {
		return COLUMN_COUNT;
	}

	public Object getValueAt(int row, int column) {
		String retval = "error";
		try {
			Message message = data[row];
			switch (column) {
			case 0:
				retval = message.isSet(Flag.SEEN)?"":"N";
				break;
			case 1:
				retval = message.getSubject();
				break;
			case 2:
				retval = message.getReplyTo()[0].toString();
				break;
			case 3:
				retval = message.getReceivedDate().toString();
				break;
			}
		} catch (MessagingException e) {
			e.printStackTrace();
		}
		return retval;
	}

	public Class getColumnClass(int column) {
		return String.class;
	}

	public String getColumnName(int column) {
		return columnNames[column];
	}
}
